package com.itlangzi.mybatis.dialect.helper;

import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.parser.SQLParserUtils;
import com.alibaba.druid.sql.parser.SQLStatementParser;

/**
 * 方言工具类
 */
public class DialectHelper {

	private DialectHelper(){}

	public static String getNoneOrderBySQL(String originalSQL, String dbType) {
		SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(originalSQL, dbType);
		SQLSelectStatement statement = (SQLSelectStatement) parser.parseStatement();
		SQLSelectQueryBlock queryBlock = statement.getSelect().getQueryBlock();
		queryBlock.setOrderBy(null);
		return statement.toString();
	}
}
